/**********************************************************************
* Filename: Continente.java
* Created: 2012/04/23
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.copaPaises.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Continente
{
	public static Set<Continente> allInstances = new HashSet<Continente>();
	
	private String nome;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Continente()
	{
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param nome the nome to initialize
	**********************************************************************/
	public Continente(String nome)
	{
		this.nome = nome;
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the nome of the continente
	**********************************************************************/
	public String nome()
	{
		return nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param nome the nome to set
	**********************************************************************/
	public void setNome(String nome)
	{
		this.nome = nome;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Continente[1] <-> Pais[*]
	* @return the paises of the continente
	**********************************************************************/
	public Set<Pais> paises()
	{
		Set<Pais> result = new HashSet<Pais>();
		for (Pais x : Pais.allInstances)
			if (x.continente()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Continente[1] <-> Pais[*]
	* @param paises the paises to set
	**********************************************************************/
	public void setPaises(Set<Pais> paises)
	{
		for (Pais x : paises)
			x.setContinente(this);
	}
	

	
	/* (non-Javadoc)
	* @see java.lang.Object#toString()
	*/
	@Override
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Continente [nome=" + nome + "]\n";
	}
	
}
